﻿Public Class frmSA_AED

    Private Sub btnClose_Click(sender As Object, e As EventArgs) Handles btnClose.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub
    Private Sub frmSA_AED_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Me.StartPosition = FormStartPosition.CenterScreen
        LoadProvince()
        LoadSex()
    End Sub
    Public Sub LoadProvince()
        cboProvince.DisplayMember = "pro_Name"
        cboProvince.ValueMember = "Pro_Id"
        cboProvince.DataSource = Cmd.ExecuteDataTable("select * from tblProvice where Active = 1")
    End Sub
    Public Sub LoadSex()
        cboSex.DisplayMember = "sex"
        cboSex.ValueMember = "sex_id"
        cboSex.DataSource = Cmd.ExecuteDataTable("select * from tblsex where Active = 1")
    End Sub
    Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter

    End Sub

    Private Sub Parameter()
        Cmd.Parameters("@SA_code") = txtSACode.Text
        Cmd.Parameters("@SA_name") = txtSAName.Text
        Cmd.Parameters("@Sex_id") = cboSex.SelectedValue
        Cmd.Parameters("@phone") = txtTel.Text
        Cmd.Parameters("@email") = txtEmail.Text
        Cmd.Parameters("@Provice_Id") = cboProvince.SelectedValue
        Cmd.Parameters("@isaddress") = txtAdr.Text
    End Sub

    Private Sub btnEdite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdite.Click
        If txtSACode.Text = "" Then

        End If

        If btnEdite.Text = "កែប្រែ" Then
            Cmd.Parameters("@SA_id") = txtID.Text
            Parameter()
            Cmd.ExecuteNonQuery("UPDATE tblSA SET SA_code = @SA_code, SA_name = @SA_name, Sex_id=@Sex_id ,phone = @phone,email = @email, Provice_Id = @Provice_Id, isaddress= @isaddress where SA_id=@SA_id ")
            frmSA_Viewer.LoadData()
            MsgBox("Updated..!")
        Else
            Parameter()
            Cmd.ExecuteNonQuery("INSERT INTO tblSA VALUES (@SA_code, @SA_name,@Sex_id , @phone,@email, @Provice_Id,@isaddress,1) ")
            MsgBox("Save Success...!")
        End If
        Me.Close()
    End Sub
End Class